package com.service;

import com.dao.UserDao;

import javax.jws.WebService;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author hecn
 * @version 1.0
 * @date 2020/8/2 0002 0:54
 */
@WebService(name = "Ajax_Test_Servlet")
public class Ajax_Test_Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");

        PrintWriter out = response.getWriter();
        String name = request.getParameter("name");
        if ("".equals(name) || "".equals(name.trim())) {
            out.println("<font color=red>用户名不能为空</font>");
        } else {
            UserDao userDao = new UserDao();
            boolean exist = userDao.isExist(name);
            if (!exist) {
                out.println("<font color=red>用户已存在</font>");
            }
        }
    }

}
